#include <Utility.hpp>
#include <cstdlib>
#include <Trie.hpp>
#include <algorithm>
#include <utility>

std::string Utility::randomWord(bool insensitive) {
	char buffer[6];
	// int qtyLetters = (rand() % 5) + 1;
	int qtyLetters = 5;
	for (int i = 0; i < qtyLetters; i++)
		buffer[i] = Trie::convertToChar(rand() % (insensitive ? 26 : 52));
	buffer[qtyLetters] = 0;
	return std::string(buffer);
}

void Utility::split(
Trie* pieces,
GTrie<int>* ppieces,
std::vector<std::string>& words,
std::vector<int>& qty) {

	for (int i = 0; i < words.size(); i++) {

		for (int begin = 0;
			begin < words[i].size();
			begin += 5) {
			int lastp1 = std::min(begin+5, (int)words[i].size());
			std::string path = 
				words[i].substr(begin, lastp1 - begin);

				ppieces->insert(path, i);
				pieces->insert(path);
				qty[i]++;
		}
	}
}
